package com.example.administrator.produceqr;

import android.Manifest;
import android.app.Activity;
import android.content.Context;

import com.tbruyelle.rxpermissions2.Permission;
import com.tbruyelle.rxpermissions2.RxPermissions;

import io.reactivex.functions.Consumer;

/**
 * Created by Administrator on 2017/6/9 0009.
 * 动态权限工具
 */

public class RxPremissionUtils {

    public void requestPermissions(Context context) {
        RxPermissions rxPermission = new RxPermissions((Activity) context);
        rxPermission
                .requestEach(Manifest.permission.INTERNET,
                        Manifest.permission.WRITE_CONTACTS,
                        Manifest.permission.READ_CONTACTS,
                        Manifest.permission.READ_EXTERNAL_STORAGE,
                        Manifest.permission.WRITE_EXTERNAL_STORAGE,
                        Manifest.permission.CALL_PHONE

                )
                .subscribe(new Consumer<Permission>() {
                    @Override
                    public void accept(Permission permission) throws Exception {
                        if (permission.granted) {

                        } else if (permission.shouldShowRequestPermissionRationale) {

                        } else {

                        }
                    }
                });
    }
}
